package com.tac.service.mes.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tac.common.result.Result;
import com.tac.dao.mes.BomDao;
import com.tac.dao.mes.BomMaterialDao;
import com.tac.pojo.mes.Bom;
import com.tac.pojo.mes.BomMaterial;
import com.tac.service.mes.BomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BomServiceImpl implements BomService {

    @Autowired
    private BomDao bomDao;

    @Autowired
    private BomMaterialDao bomMaterialDao;

    public Result<PageInfo<Bom> > getList(Integer pageNum, Integer pageSize, String bomName){
        PageHelper.startPage(pageNum,pageSize);
        List<Bom> list = bomDao.getList(bomName);
        PageInfo<Bom> bomPageInfo = new PageInfo<>(list);
        return Result.success(bomPageInfo);
    }

    public Result save(Bom bom){
        Integer integer = bomDao.save(bom);
        if(integer>0){
          return   Result.success(bom);
        }
        return Result.error("添加失败");
    }

    public Result update(Bom bom){
        Integer integer = bomDao.update(bom);
        if(integer>0){
            return Result.success(null);
        }
        return Result.error("更新失败");
    }

    public Result remove(List<Integer> ids){
        Integer integer = bomDao.remove(ids);
        if(integer>0){
            return Result.success(null);
        }
        return Result.error("删除失败");
    }

    public Result save2(BomMaterial bomMaterial){
        Integer integer = bomMaterialDao.save(bomMaterial);
        if(integer>0){
            return Result.success(bomMaterial);
        }
        return Result.error("添加失败");
    }

    public Result update2(BomMaterial bomMaterial){
        Integer integer = bomMaterialDao.update(bomMaterial);
        if(integer>0){
            return Result.success(null);
        }
        return Result.error("更新失败");
    }

    public Result remove2(List<Integer> ids){
        Integer integer = bomMaterialDao.remove(ids);
        if(integer>0){
            return Result.success(null);
        }
        return Result.error("删除失败");
    }
}
